package org.example.controller;


import lombok.RequiredArgsConstructor;
import org.apache.commons.lang.StringUtils;
import org.example.domain.ResponseResult;
import org.example.domain.entity.Message;
import org.example.enums.AppHttpCodeEnum;
import org.example.exception.SystemException;
import org.example.service.MessageService;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/message")
@RequiredArgsConstructor
public class MessageController {

    private final MessageService messageService;

    @PostMapping("/sendMessage")
    public ResponseResult sendMessage(@RequestBody Message message){
        if(StringUtils.isBlank(message.getContent())){
            throw new SystemException(AppHttpCodeEnum.NOT_MESSAGE_CONTENT_ERROR);
        }
        return messageService.sendMessage(message);
    }

    @GetMapping("/allMessageList")
    public ResponseResult allMessageList(){
        return messageService.allMessageList();
    }
}
